﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using SimpleLibrary.Components;

namespace SimpleLibrary.Convertors
{
    class UserConvertor : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                List<UserListItem> collection = new List<UserListItem>();

                DataView view = value as DataView;
                if (view != null)
                    foreach (DataRowView dataView in view)
                    {
                        UserListItem item = new UserListItem();
                        item.Style = MainScreen.Instance.Resources["SimpleListBoxItem"] as Style;

                        item.UserName = dataView["strName"].ToString();
                        item.ID = dataView["ID"].ToString();
                        item.PhoneNo = dataView["strPhoneNo"].ToString();
                        item.Address = dataView["strAddress"].ToString();
                        item.MailId = dataView["strMailId"].ToString();
                        collection.Add(item);
                    }
                return collection;
            }
            return new object();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
